package com.fg.fgmall.controller;

import com.fg.fgmall.common.R;
import com.fg.fgmall.entity.Product;
import com.fg.fgmall.service.HomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/home")
public class HomeController {

    @Autowired
    private HomeService homeService;

    // 查询首页新推荐的商品
    @GetMapping("/new")
    public R homeNew() {

        try {
            List<Product> products = homeService.selectNewProducts();
            return R.ok(products);
        } catch (Exception e) {
            return R.error();
        }

    }

    // 查询首页新推荐的商品
    @GetMapping("/hot")
    public R homeHot() {

        try {
            List<Product> products = homeService.selectHotProducts();
            return R.ok(products);
        } catch (Exception e) {
            return R.error();
        }

    }

}
